<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html
    PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<!-- /fasttmp/mkdist-qt-4.3.5-1211793125/qtopia-core-opensource-src-4.3.5/doc/src/unicode.qdoc -->
<head>
  <title>Qt 4.3: Unicode</title>
  <link href="classic.css" rel="stylesheet" type="text/css" />
</head>
<body>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td align="left" valign="top" width="32"><a href="http://www.trolltech.com/products/qt"><img src="images/qt-logo.png" align="left" width="32" height="32" border="0" /></a></td>
<td width="1">&nbsp;&nbsp;</td><td class="postheader" valign="center"><a href="index.html"><font color="#004faf">Home</font></a>&nbsp;&middot; <a href="classes.html"><font color="#004faf">All&nbsp;Classes</font></a>&nbsp;&middot; <a href="mainclasses.html"><font color="#004faf">Main&nbsp;Classes</font></a>&nbsp;&middot; <a href="groups.html"><font color="#004faf">Grouped&nbsp;Classes</font></a>&nbsp;&middot; <a href="modules.html"><font color="#004faf">Modules</font></a>&nbsp;&middot; <a href="functions.html"><font color="#004faf">Functions</font></a></td>
<td align="right" valign="top" width="230"><a href="http://www.trolltech.com"><img src="images/trolltech-logo.png" align="right" width="203" height="32" border="0" /></a></td></tr></table><h1 align="center">Unicode<br /><small></small></h1>
<p>Unicode is a multi-byte character set, portable across all major computing platforms and with decent coverage over most of the world. It is also single-locale; it includes no code pages or other complexities that make software harder to write and test. There is no competing character set that's reasonably cross-platform. For these reasons, Trolltech uses Unicode 4.0 as the native character set for Qt.</p>
<a name="information-about-unicode-on-the-web"></a>
<h3>Information about Unicode on the Web</h3>
<p>The <a href="http://www.unicode.org/">Unicode Consortium</a> has a number of documents available, including</p>
<ul>
<li><a href="http://www.unicode.org/unicode/standard/principles.html">A technical introduction to Unicode</a></li>
<li><a href="http://www.unicode.org/unicode/standard/standard.html">The home page for the standard</a></li>
</ul>
<a name="the-standard"></a>
<h3>The Standard</h3>
<p>The current version of the standard is 4.0&#x2e;0&#x2e;</p>
<ul>
<li><a href="http://www.amazon.com/exec/obidos/ASIN/0321185781/trolltech/t">The Unicode Standard, version 4.0&#x2e;</a> See also <a href="http://www.unicode.org/unicode/standard/versions/">its home page.</a></li>
<li><a href="http://www.amazon.com/exec/obidos/ASIN/0201616335/trolltech/t">The Unicode Standard, version 3.2&#x2e;</a></li>
<li><a href="http://www.amazon.com/exec/obidos/ASIN/0201473459/trolltech/t">The Unicode Standard, version 2.0&#x2e;</a> See also the <a href="http://www.unicode.org/unicode/reports/tr8.html">2.1 update</a> and <a href="http://www.unicode.org/unicode/standard/versions/enumeratedversions.html#Unicode">2.1&#x2e;9 the 2.1&#x2e;9 data files</a> at www.unicode.org.</li>
</ul>
<a name="unicode-in-qt"></a>
<h3>Unicode in Qt</h3>
<p>In Qt, and in most applications that use Qt, most or all user-visible strings are stored using Unicode. Qt provides:</p>
<ul>
<li>Translation to/from legacy encodings for file I/O: see <a href="qtextcodec.html">QTextCodec</a> and <a href="qtextstream.html">QTextStream</a>.</li>
<li>Translation from Input Methods and 8-bit keyboard input.</li>
<li>Translation to legacy character sets for on-screen display.</li>
<li>A string class, <a href="qstring.html">QString</a>, that stores Unicode characters, with support for migrating from C strings including fast (cached) translation to and from US-ASCII, and all the usual string operations.</li>
<li>Unicode-aware widgets where appropriate.</li>
<li>Unicode support detection on Windows, so that Qt provides Unicode even on Windows platforms that do not support it natively.</li>
</ul>
<p>To fully benefit from Unicode, we recommend using <a href="qstring.html">QString</a> for storing all user-visible strings, and performing all text file I/O using <a href="qtextstream.html">QTextStream</a>. Use <a href="qkeyevent.html#text">QKeyEvent::text</a>() for keyboard input in any custom widgets you write; it does not make much difference for slow typists in Western Europe or North America, but for fast typists or people using special input methods using text() is beneficial.</p>
<p>All the function arguments in Qt that may be user-visible strings, <a href="qlabel.html#text-prop">QLabel::setText</a>() and a many others, take <tt>const QString &amp;</tt>s. <a href="qstring.html">QString</a> provides implicit casting from <tt>const char *</tt> so that things like</p>
<pre> label-&gt;setText(&quot;Password:&quot;);</pre>
<p>will work. There is also a function, <a href="qobject.html#tr">QObject::tr</a>(), that provides translation support, like this:</p>
<pre> label-&gt;setText(tr(&quot;Password:&quot;));</pre>
<p><a href="qobject.html#tr">QObject::tr</a>() maps from <tt>const char *</tt> to a Unicode string, and uses installable <a href="qtranslator.html">QTranslator</a> objects to do the mapping.</p>
<p>Qt provides a number of built-in <a href="qtextcodec.html">QTextCodec</a> classes, that is, classes that know how to translate between Unicode and legacy encodings to support programs that must talk to other programs or read/write files in legacy file formats.</p>
<p>By default, conversion to/from <tt>const char *</tt> uses a locale-dependent codec. However, applications can easily find codecs for other locales, and set any open file or network connection to use a special codec. It is also possible to install new codecs, for encodings that the built-in ones do not support. (At the time of writing, Vietnamese/VISCII is one such example.)</p>
<p>Since US-ASCII and ISO-8859-1 are so common, there are also especially fast functions for mapping to and from them. For example, to open an application's icon one might do this:</p>
<pre> QFile file(QString::fromLatin1(&quot;appicon.png&quot;));</pre>
<p>or</p>
<pre> QFile file(QLatin1String(&quot;appicon.png&quot;));</pre>
<p>Regarding output, Qt will do a best-effort conversion from Unicode to whatever encoding the system and fonts provide. Depending on operating system, locale, font availability, and Qt's support for the characters used, this conversion may be good or bad. We will extend this in upcoming versions, with emphasis on the most common locales first.</p>
<p>See also <a href="i18n.html">Internationalization with Qt</a>.</p>
<p /><address><hr /><div align="center">
<table width="100%" cellspacing="0" border="0"><tr class="address">
<td width="30%">Copyright &copy; 2008 <a href="trolltech.html">Trolltech</a></td>
<td width="40%" align="center"><a href="trademarks.html">Trademarks</a></td>
<td width="30%" align="right"><div align="right">Qt 4.3.5</div></td>
</tr></table></div></address></body>
</html>
